package com.his.j259w264.controller;

import com.his.j259w264.pojo.Department;
import com.his.j259w264.service.impl.DepartmentServiceImpl;
import io.swagger.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 科室(Department)表控制层
 *
 * @author EdgeYu
 * @version 1.0
 * @since 2021-09-15 19:41:49
 */

@RestController
@RequestMapping("/department")
@Api(value = "科室(Department)管理", tags = "科室(Department)管理接口API")
@ApiResponses({
        @ApiResponse(code = 400, message = "请求参数不完整或者错误"),
        @ApiResponse(code = 404, message = "找不到页面"),
        @ApiResponse(code = 405, message = "请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code = 406, message = "页面地址和接口名冲突"),
        @ApiResponse(code = 415, message = "请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code = 500, message = "后台服务逻辑错误")
})
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentServiceImpl departmentServiceImpl;

    /**
     * 分页查询所有科室信息
     *
     * @param index          需要查询的页码
     * @param limit          分页数量
     * @param departmentName 模糊查询科室名称
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询所有科室信息接口", notes = "分页查询所有科室信息接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int", required = true, example = "1"),
            @ApiImplicitParam(name = "name", value = "科室名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "分页数量", paramType = "query", dataType = "int", required = true, example = "10")
    })
    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index, @RequestParam(name = "limit") int limit, String departmentName) {
        return this.departmentServiceImpl.selectForPage(index, limit, departmentName);
    }

    /**
     * 分页查询当前科室的病人未接诊的挂号信息
     * sex 中 0 为女性，1 为男性
     * receptionState 0 为 待诊，1 为已接诊
     * 如不选择接诊状态，默认为待诊
     *
     * @param index           需要查询的页码
     * @param limit           分页数量
     * @param dependentId     科室id
     * @param startTime       起始时间
     * @param endTime         结束时间
     * @param patientName     病人姓名
     * @param idCard          病人身份证号
     * @param serialNo        流水号
     * @param sex             病人性别
     * @param phone           联系电话
     * @param medicalRecordNo 病案号
     * @param receptionState  接诊状态
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageByDepartmentId", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询当前科室的病人未接诊的挂号信息及病历信息接口", notes = "分页查询当前科室的病人未接诊的挂号信息及病历信息接口, " +
            "sex 中 0 为女性，1 为男性 receptionState 0 为 待诊，1 为已接诊,如不选择接诊状态，默认为待诊 时间格式为 yyyy-MM-dd HH:mm:ss", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int", required = true, example = "1"),
            @ApiImplicitParam(name = "limit", value = "分页数量", paramType = "query", dataType = "int", required = true, example = "10"),
            @ApiImplicitParam(name = "dependentId", value = "科室id", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "startTime", value = "起始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "patientName", value = "病人姓名", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "idCard", value = "病人身份证号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "serialNo", value = "流水号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sex", value = "病人性别", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "phone", value = "联系电话", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "medicalRecordNo", value = "病案号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "receptionState", value = "接诊状态", paramType = "query", dataType = "int", example = "0")
    })
    public Map<String, Object> selectForPageByDepartmentId(@RequestParam(name = "page") int index, @RequestParam(name = "limit") int limit,
                                                           @RequestParam(name = "dependentId") String dependentId, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") String startTime,
                                                           @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") String endTime, String patientName, String idCard, String serialNo,
                                                           Integer sex, String phone, String medicalRecordNo, @RequestParam(defaultValue = "0") Integer receptionState) {
        return departmentServiceImpl.selectForPageByDepartmentId(index,  limit, dependentId, startTime, endTime,patientName, idCard, serialNo,
                 sex,  phone,  medicalRecordNo, receptionState);
    }


    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键删除一条科室(Department记录的接口)", notes = "根据一个主键删除一条科室(Department记录的接口)", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", paramType = "query", dataType = "String", required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") Integer id) {
        return this.departmentServiceImpl.deleteById(id);
    }


    /**
     * 通过主键更新单条数据
     *
     * @param department 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个科室(Department的接口)", notes = "通过主键更新一个科室(Department的接口)", httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "department", value = "pojo模型", required = true) Department department) {
        return this.departmentServiceImpl.updateById(department);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param department 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个科室(Department的接口)", notes = "根据完整记录新增一个科室(Department的接口)", httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "department", value = "pojo模型", required = true) Department department) {
        return this.departmentServiceImpl.insert(department);
    }

}
